import service from "@/api/service";

export default {
  namespaced: true,
  state: {
    commandTypes: [
      {
        value: "Text",
        label: "Text",
      },
      {
        value: "StoredProcedure",
        label: "StoredProcedure",
      },
      {
        value: "TableDirect",
        label: "TableDirect",
      },
    ],
    parameterDirections: [
      {
        value: "Input",
        label: "Input",
      },
      {
        value: "Output",
        label: "Output",
      },
      {
        value: "InputOutput",
        label: "InputOutput",
      },
      {
        value: "ReturnValue",
        label: "ReturnValue",
      },
    ],
    providers: [],
    connections: [],
  },
  mutations: {
    DATA_PROVIDERS(state, providers) {
      state.providers = providers;
    },
    CONNECTIONS(state, connections) {
      state.connections = connections;
    },
  },
  actions: {
    dataProviders({ commit, state }) {
      return new Promise((resolve, reject) => {
        service.connection
          .providers()
          .then((response) => {
            commit("DATA_PROVIDERS", response.success ? response.data : null);
            resolve(response);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    queryConnections({ commit, state }) {
      return new Promise((resolve, reject) => {
        service.connection
          .query({ data: { parameters: { keyword: null } } })
          .then((response) => {
            commit("CONNECTIONS", response.success ? response.data : null);
            resolve(response);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
  },
};
